package com.wlb365.financing.modules.trade.service.impl;

import com.google.common.collect.Maps;
import com.wlb365.financing.common.utils.StringUtils;
import com.wlb365.financing.modules.trade.request.data.QueryInfoByKeyAndBtypeReq;
import com.wlb365.financing.modules.trade.request.data.QuerySchemaByBtypeReq;
import com.wlb365.financing.modules.trade.request.data.QuerySchemaByIdReq;
import com.wlb365.financing.modules.trade.response.data.QueryInfoByKeyAndBtypeRes;
import com.wlb365.financing.modules.trade.response.data.QuerySchemaByBtypeRes;
import com.wlb365.financing.common.utils.SdkHelper;
import com.wlb365.financing.modules.trade.response.data.QuerySchemaByIdRes;
import com.wlb365.financing.modules.trade.service.IDataService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 数据中心服务实现类.
 *
 * @author zwh
 * @version 1.0
 */
@Service
public class DataService implements IDataService {

    @Override
    public QuerySchemaByIdRes querySchemaById(String templateId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("id", templateId);
        return SdkHelper.execute(new QuerySchemaByIdReq(), params);
    }

    @Override
    public QuerySchemaByBtypeRes querySchema(final String dataType, final String subscribeBy) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("templateBtype", dataType);
        if (StringUtils.isNotEmpty(subscribeBy)) {
            params.put("subscribeBy", subscribeBy);
        }
        return SdkHelper.execute(new QuerySchemaByBtypeReq(), params);
    }

    @Override
    public QueryInfoByKeyAndBtypeRes querySchemaData(final String key, final String dataType) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("key", key);
        params.put("btype", dataType);
        return SdkHelper.execute(new QueryInfoByKeyAndBtypeReq(), params);
    }

}
